<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="所属功能" prop="functionId">
        <el-select v-model="queryParams.functionId" placeholder="请选择所属功能" clearable>
          <el-option
            v-for="dict in dict.type.vFunction"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="F1" prop="f1">
        <el-input
          v-model="queryParams.f1"
          placeholder="请输入F1"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="F2" prop="f2">
        <el-input
          v-model="queryParams.f2"
          placeholder="请输入F2"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="F3" prop="f3">
        <el-input
          v-model="queryParams.f3"
          placeholder="请输入F3"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="F4" prop="f4">
        <el-input
          v-model="queryParams.f4"
          placeholder="请输入F4"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="F5" prop="f5">
        <el-input
          v-model="queryParams.f5"
          placeholder="请输入F5"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="F6" prop="f6">
        <el-input
          v-model="queryParams.f6"
          placeholder="请输入F6"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="F7" prop="f7">
        <el-input
          v-model="queryParams.f7"
          placeholder="请输入F7"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="F8" prop="f8">
        <el-input
          v-model="queryParams.f8"
          placeholder="请输入F8"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="F9" prop="f9">
        <el-input
          v-model="queryParams.f9"
          placeholder="请输入F9"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="F10" prop="f10">
        <el-input
          v-model="queryParams.f10"
          placeholder="请输入F10"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="F11" prop="f11">
        <el-input
          v-model="queryParams.f11"
          placeholder="请输入F11"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="F12" prop="f12">
        <el-input
          v-model="queryParams.f12"
          placeholder="请输入F12"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="F13" prop="f13">
        <el-input
          v-model="queryParams.f13"
          placeholder="请输入F13"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="F14" prop="f14">
        <el-input
          v-model="queryParams.f14"
          placeholder="请输入F14"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="说明" prop="describe">
        <el-input
          v-model="queryParams.describe"
          placeholder="请输入说明"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['fpa:functionVaf:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['fpa:functionVaf:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['fpa:functionVaf:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['fpa:functionVaf:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="functionVafList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" align="center" prop="id" />
      <el-table-column label="所属功能" align="center" prop="functionId">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.vFunction" :value="scope.row.functionId"/>
        </template>
      </el-table-column>
      <el-table-column label="F1" align="center" prop="f1" />
      <el-table-column label="F2" align="center" prop="f2" />
      <el-table-column label="F3" align="center" prop="f3" />
      <el-table-column label="F4" align="center" prop="f4" />
      <el-table-column label="F5" align="center" prop="f5" />
      <el-table-column label="F6" align="center" prop="f6" />
      <el-table-column label="F7" align="center" prop="f7" />
      <el-table-column label="F8" align="center" prop="f8" />
      <el-table-column label="F9" align="center" prop="f9" />
      <el-table-column label="F10" align="center" prop="f10" />
      <el-table-column label="F11" align="center" prop="f11" />
      <el-table-column label="F12" align="center" prop="f12" />
      <el-table-column label="F13" align="center" prop="f13" />
      <el-table-column label="F14" align="center" prop="f14" />
      <el-table-column label="说明" align="center" prop="describe" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['fpa:functionVaf:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['fpa:functionVaf:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改VAF对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="所属功能" prop="functionId">
          <el-select v-model="form.functionId" placeholder="请选择所属功能">
            <el-option
              v-for="dict in dict.type.vFunction"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="F1" prop="f1">
          <el-input v-model="form.f1" placeholder="请输入F1" />
        </el-form-item>
        <el-form-item label="F2" prop="f2">
          <el-input v-model="form.f2" placeholder="请输入F2" />
        </el-form-item>
        <el-form-item label="F3" prop="f3">
          <el-input v-model="form.f3" placeholder="请输入F3" />
        </el-form-item>
        <el-form-item label="F4" prop="f4">
          <el-input v-model="form.f4" placeholder="请输入F4" />
        </el-form-item>
        <el-form-item label="F5" prop="f5">
          <el-input v-model="form.f5" placeholder="请输入F5" />
        </el-form-item>
        <el-form-item label="F6" prop="f6">
          <el-input v-model="form.f6" placeholder="请输入F6" />
        </el-form-item>
        <el-form-item label="F7" prop="f7">
          <el-input v-model="form.f7" placeholder="请输入F7" />
        </el-form-item>
        <el-form-item label="F8" prop="f8">
          <el-input v-model="form.f8" placeholder="请输入F8" />
        </el-form-item>
        <el-form-item label="F9" prop="f9">
          <el-input v-model="form.f9" placeholder="请输入F9" />
        </el-form-item>
        <el-form-item label="F10" prop="f10">
          <el-input v-model="form.f10" placeholder="请输入F10" />
        </el-form-item>
        <el-form-item label="F11" prop="f11">
          <el-input v-model="form.f11" placeholder="请输入F11" />
        </el-form-item>
        <el-form-item label="F12" prop="f12">
          <el-input v-model="form.f12" placeholder="请输入F12" />
        </el-form-item>
        <el-form-item label="F13" prop="f13">
          <el-input v-model="form.f13" placeholder="请输入F13" />
        </el-form-item>
        <el-form-item label="F14" prop="f14">
          <el-input v-model="form.f14" placeholder="请输入F14" />
        </el-form-item>
        <el-form-item label="说明" prop="describe">
          <el-input v-model="form.describe" placeholder="请输入说明" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listFunctionVaf, getFunctionVaf, delFunctionVaf, addFunctionVaf, updateFunctionVaf } from "@/api/fpa/functionVaf";

export default {
  name: "FunctionVaf",
  dicts: ['vFunction'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // VAF表格数据
      functionVafList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        functionId: null,
        f1: null,
        f2: null,
        f3: null,
        f4: null,
        f5: null,
        f6: null,
        f7: null,
        f8: null,
        f9: null,
        f10: null,
        f11: null,
        f12: null,
        f13: null,
        f14: null,
        describe: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        functionId: [
          { required: true, message: "所属功能不能为空", trigger: "change" }
        ],
        f1: [
          { required: true, message: "F1不能为空", trigger: "blur" }
        ],
        f2: [
          { required: true, message: "F2不能为空", trigger: "blur" }
        ],
        f3: [
          { required: true, message: "F3不能为空", trigger: "blur" }
        ],
        f4: [
          { required: true, message: "F4不能为空", trigger: "blur" }
        ],
        f5: [
          { required: true, message: "F5不能为空", trigger: "blur" }
        ],
        f6: [
          { required: true, message: "F6不能为空", trigger: "blur" }
        ],
        f7: [
          { required: true, message: "F7不能为空", trigger: "blur" }
        ],
        f8: [
          { required: true, message: "F8不能为空", trigger: "blur" }
        ],
        f9: [
          { required: true, message: "F9不能为空", trigger: "blur" }
        ],
        f10: [
          { required: true, message: "F10不能为空", trigger: "blur" }
        ],
        f11: [
          { required: true, message: "F11不能为空", trigger: "blur" }
        ],
        f12: [
          { required: true, message: "F12不能为空", trigger: "blur" }
        ],
        f13: [
          { required: true, message: "F13不能为空", trigger: "blur" }
        ],
        f14: [
          { required: true, message: "F14不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询VAF列表 */
    getList() {
      this.loading = true;
      listFunctionVaf(this.queryParams).then(response => {
        this.functionVafList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        functionId: null,
        f1: null,
        f2: null,
        f3: null,
        f4: null,
        f5: null,
        f6: null,
        f7: null,
        f8: null,
        f9: null,
        f10: null,
        f11: null,
        f12: null,
        f13: null,
        f14: null,
        describe: null,
        isExtended: null,
        extendType: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加VAF";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getFunctionVaf(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改VAF";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateFunctionVaf(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addFunctionVaf(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除VAF编号为"' + ids + '"的数据项？').then(function() {
        return delFunctionVaf(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('fpa/functionVaf/export', {
        ...this.queryParams
      }, `functionVaf_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
